package wafa.implementation.gedAPI;

import wafa.exceptions.AFamilyNotFound;
import wafa.gedInterface.GedService;
import wafa.modelDocument.Content;
import wafa.modelDocument.Document;


public class ServiceGedImplICM implements GedService  {

	String database = "serverged30";
	String userName = "icmadmin";
	String password = "icmadmin";
	String schema = "SCHEMA=" + "ICMADMIN";

   @Override
	public void addDocument(Document document) throws AFamilyNotFound{
		// TODO Auto-generated method stub
//		try {
//			DKDatastoreICM dsICM = new DKDatastoreICM();
//			dsICM.connect(database, userName, password, schema);
//			DKDDO ddo = dsICM.createDDO(document.getFamily().getFamilyName(),
//					DKConstant.DK_CM_DOCUMENT);
//
//			System.out.println("start" + document.getFamily().getFamilyName());
//
//			// add indexes to DDO
//			addIndexesToDDO(document, ddo);
//
//			DKParts dkParts = (DKParts) ddo.getData(ddo.dataId(
//					DKConstant.DK_CM_NAMESPACE_ATTR, DKConstant.DK_CM_DKPARTS));
//			// add content to DDO
//			addContentToDDO(document, dkParts, dsICM);
//			// add attachements to DDO
//			addAttachementsToDDO(document, dkParts, dsICM);
//			System.out.println("chui laaaaa::::::::::::::::"
//					+ dkParts.cardinality());
//			// add DDO to CM
//			ddo.add();
//
//			dsICM.disconnect();
//			dsICM.destroy();
//
//		} catch (DKException e) {
//
//	
//	    	     if(e.getErrorId()==400){
//	    	    	 
//	    	    	 throw new AFamilyNotFound("family not found!!!");
//	    	     }
//			// TODO Auto-generated catch block
//		//	e.printStackTrace();
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
//	private void addContentToDDO(Document document, DKParts dkParts,
//			DKDatastoreICM dsICM) throws DKException, Exception {
//
//		DKLobICM documentContent = (DKLobICM) dsICM.createDDO("ICMBASE",
//				DKConstant.DK_CM_ITEM);
//		documentContent.setContent(document.getContent().getContent());
//		documentContent.setMimeType(document.getContent().getMimeType());
//		dkParts.addElement(documentContent);
//		System.out.println("fin add content");
//
//	}
//
//	private void addAttachementsToDDO(Document document, DKParts dkParts,
//			DKDatastoreICM dsICM) throws DKException, Exception {
//		DKLobICM attachmentXdo;
//		for (Content attachment : document.getAttachments()) {
//			attachmentXdo = (DKLobICM) dsICM.createDDO("ICMBASE",
//					DKConstant.DK_CM_ITEM);
//			attachmentXdo.setContent(attachment.getContent());
//			attachmentXdo.setMimeType(attachment.getMimeType());
//			dkParts.addElement(attachmentXdo);
//
//		}
//		System.out.println("fin add atta");
//	}
//
//	private void addIndexesToDDO(Document document, DKDDO item)
//			throws DKUsageError {
//		for (Index<?> index : document.getFamily().getIndexes()) {
//			item.setData(item.dataId(DKConstant.DK_CM_NAMESPACE_ATTR,
//					index.getKey()), index.getValue());
//		}
//		System.out.println("fin add index");
//	}
//


	@Override
	public void deletedocument(String id) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public Content getContentById(String id) {
		// TODO Auto-generated method stub
		return null;
	}

}
